package com.alameda.commonpent.job;

import com.alameda.base.constant.ProjectConstant;
import com.alameda.commonpent.event.publisher.EventPublisher;
import com.alameda.utils.MapUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 定时任务组件
 *
 * @author Lv
 * @date 2024/7/23
 */
@SuppressWarnings("all")
@Slf4j
@Component
public class JobCommonpent implements Job {

    @Autowired
    private EventPublisher eventPublisher;

    /**
     * 执行定时任务
     *
     * @param jobExecutionContext 定时任务执行上下文对象
     * @throws JobExecutionException 定时任务执行异常对象
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 封装删除操作记录事件内容
        Map<String, Object> map = MapUtils.newHashMap();
        map.put(ProjectConstant.OperateInfoPropertyConstant.SQL, ProjectConstant.OperateInfoPropertyConstant.DELETE_SQL);
        map.put(ProjectConstant.StrategyConstant.LISTEN_STRATEGY, ProjectConstant.StrategyConstant.REMOVE_OPERATE_STRATEGY);
        // 发布删除操作记录事件
        eventPublisher.publish(JSONObject.toJSONString(map));
    }
}
